Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@textlint/markdown-to-ast
Advanced tools
@textlint/markdown-to-ast is an npm package that converts Markdown text into an Abstract Syntax Tree (AST). This is particularly useful for text processing, linting, and transforming Markdown content programmatically.
Convert Markdown to AST
This feature allows you to convert a Markdown string into an Abstract Syntax Tree (AST). The AST can then be used for further processing, such as linting or transforming the Markdown content.
const markdownToAst = require('@textlint/markdown-to-ast');
const markdownText = '# Hello World\nThis is a sample markdown text.';
const ast = markdownToAst.parse(markdownText);
console.log(JSON.stringify(ast, null, 2));
remark-parse is a Markdown parser built on top of the unified framework. It converts Markdown text into a syntax tree, similar to @textlint/markdown-to-ast. However, it is part of a larger ecosystem of plugins that can be used for various text processing tasks.
markdown-it is a fast and flexible Markdown parser. It converts Markdown text into HTML and can be extended with plugins. While it does not directly produce an AST, it can be used in conjunction with other tools to achieve similar functionality.
marked is a low-level Markdown compiler that allows for extensive customization. It can parse Markdown into HTML and also provides an option to generate an AST, making it comparable to @textlint/markdown-to-ast.
Parse Markdown to AST with location info.
This library is not parser itself, it dependent on wooorm/remark.
Markdown -> remark -> markdown-to-ast ->
TxtNode
s
The AST consists of TxtNode
s.
A TxtNode
of the AST has following properties:
loc
- Nodes have line and column-based location info.range
- Nodes have an index-based location range (array).raw
- Node have a raw
text.value
- Node have a value
of text.The interface are defined in textlint/txtnode.md
This library is a part of textlint/textlint.
If you need to markdown parser, please use wooorm/remark directly.
npm install @textlint/markdown-to-ast
var parse = require("@textlint/markdown-to-ast").parse;
var markdown = "It's a *text*";
var AST = parse(markdown);
/*
{
"type": "Document",
"children": [
{
"type": "Paragraph",
"children": [
{
"type": "Str",
"value": "It's a ",
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 7
}
},
"range": [
0,
7
],
"raw": "It's a "
},
{
"type": "Emphasis",
"children": [
{
"type": "Str",
"value": "text",
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 12
}
},
"range": [
8,
12
],
"raw": "text"
}
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 13
}
},
"range": [
7,
13
],
"raw": "*text*"
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"range": [
0,
13
],
"raw": "It's a *text*"
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 13
}
},
"range": [
0,
13
],
"raw": "It's a *text*"
}
*/
If you want to know real use-case, please see textlint/textlint.
npm test
See tools/ directory.
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT
FAQs
Parse Markdown to AST with location info.
The npm package @textlint/markdown-to-ast receives a total of 214,540 weekly downloads. As such, @textlint/markdown-to-ast popularity was classified as popular.
We found that @textlint/markdown-to-ast demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.